package com.lsismo.core.base.service.impl;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.lsismo.core.base.dao.UniversalDao;
import com.lsismo.core.base.service.UniversalManager;

/**
 * 业务服务层基类
 *
 */
public class UniversalManagerImpl implements UniversalManager {
    /**
     * 用于所有子类的日志变量
     */
    protected final Log log = LogFactory.getLog(getClass());

    /**
     * UniversalDao实例
     */
    protected UniversalDao dao;
 
    public void setDao(UniversalDao dao) {
        this.dao = dao;
    }

    /**
     * {@inheritDoc}
     */
    @SuppressWarnings("unchecked")
    public Object get(Class clazz, Serializable id) {
        return dao.get(clazz, id);
    }

    /**
     * {@inheritDoc}
     */
    @SuppressWarnings("unchecked")
    public List getAll(Class clazz) {
        return dao.getAll(clazz);
    }
    
    /**
     * {@inheritDoc}
     */
    @SuppressWarnings("unchecked")
    public boolean exists(Class clazz, Serializable id){
    	return dao.exists(clazz, id);
    }

    /**
     * {@inheritDoc}
     */
    @SuppressWarnings("unchecked")
    public void remove(Class clazz, Serializable id) {
        dao.remove(clazz, id);
    }
    
    /**
     * {@inheritDoc}
     */
    public void remove(Object o) {
    	dao.remove(o);
    }

    /**
     * {@inheritDoc}
     */
    public Object save(Object o) {
        return dao.save(o);
    }
    
    /**
     * {@inheritDoc}
     */
    @SuppressWarnings("unchecked")
    public List findByExample(Object o) {
    	return dao.findByExample(o);
    }
    
    /**
     * {@inheritDoc}
     */
    @SuppressWarnings("unchecked")
    public List findByProperty(Class clazz, String propertyName, Object value) {
    	return dao.findByProperty(clazz, propertyName, value);
    }
    
    /**
     * {@inheritDoc}
     */
    @SuppressWarnings("unchecked")
    public List find(String hql, Object... values) {
    	return dao.find(hql, values);
    }
  
    /**
     * {@inheritDoc}
     */
    @SuppressWarnings("unchecked")
    public List getAllDistinct(Class clazz) {
    	return dao.getAllDistinct(clazz);
    }
	
    /**
     * {@inheritDoc}
     */
    @SuppressWarnings("unchecked")
    public List findByNamedQuery(String queryName, Map<String, Object> queryParams) throws Exception {
    	return dao.findByNamedQuery(queryName, queryParams);
    }
}
